package net.aetherial.context.grounding.estimators;

import java.util.*;

/**
 * An incomplete and untested implementation of a rule-based learner.
 */

public class RuleBasedEstimator extends AggregateEstimator
{
	private double cumulativeScore;
	private Map<Estimator, Double> scores;

	/**
	 * Constructor.
	 */
	
	public RuleBasedEstimator ()
	{
		super ();
		
		cumulativeScore = 0.0;
		scores = new HashMap<Estimator, Double> ();
	}
	
	/**
	 * Generates an aggregate estimation using a cumulative rule-based (as opposed to statistical) scheme.
	 * 
	 * @see net.aetherial.context.grounding.estimators.Estimator#estimate(java.util.HashMap)
	 */
	
	public double estimate (Map<String, Map<String, Object>> layers) 
	{
		double increase = 0.0;
		
		for (Estimator e: estimators)
		{
			double estimate = e.estimate (layers);

			Double d = scores.get (e);

			if (d != null)
			{
				increase += (estimate - d);
			}
			else
			{
				increase = estimate;
			}

			scores.put (e, estimate);
			
			cumulativeScore += increase;
		}
		
		return cumulativeScore;
	}

	/**
	 * @see net.aetherial.context.grounding.estimators.AggregateEstimator#reset()
	 */
	
	public void reset ()
	{
		super.reset ();
		
		cumulativeScore = 0.0;
	}

	/**
	 * Returns "RuleBasedEstimator".
	 * 
	 * @see net.aetherial.context.grounding.estimators.Estimator#getName()
	 */
	
	public String getName () 
	{
		return "RuleBasedEstimator";
	}

	/**
	 * @see net.aetherial.context.grounding.estimators.Estimator#estimate(java.lang.String, java.lang.String, double)
	 */
	
	public double estimate (String sender, String contribution, double score) 
	{
		return cumulativeScore;
	}
}
